package com.Imp;

import com.entity.Order;
import com.mapper.OrderMapper;
import com.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OrderMapperImpl implements OrderMapper {
    public void insertOrder(Order order) {
        // 实现插入订单操作
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.OrderMapper.insertOrder",order);
            sqlSession.commit();  // 提交事务
        }
    }

    public void updateOrder(Order order) {
        // 实现更新订单操作
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.OrderMapper.updateOrder",order);
            sqlSession.commit();  // 提交事务
        }
    }

    public void deleteOrder(int orderId) {
        // 实现删除订单操作
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.delete("com.mapper.OrderMapper.deleteOrder",orderId);
            sqlSession.commit();  // 提交事务
        }
    }

    public List<Order> getOrderByOrderId(int orderId) {
        // 实现根据订单ID查询订单操作
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()){
            return sqlSession.selectList("com.mapper.OrderMapper.getOrderByOrderId", orderId);
        }
    }
}
